// pages/mine/opinion_box/opinion_box.js
import {
  Alert,
  Confirm,
  Toast
} from 'wuss-weapp';
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    files: [],
    imagesUrls: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      theme: app.globalData.theme,
    });
    app.setNavigationBarColor();
    this.getYard();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getYard:function(){
    // app.isBindCommunity().then(result => {
    //   let data = result.data.data.list;
    //   let yardArray=[];
    //   data.forEach((item,index)=>{
    //     item["key"] = item.yard_name;
    //     item["value"] = item.area_code + "," + item.yard_id+","+item.yard_name;
    //     yardArray.push(item);
    //   });
    //   console.error(yardArray)
    //   this.setData({
    //     arrayYard: yardArray
    //   });
    // });
    // app.wxGetRequest("/mine/getYards", {
    //   area_code: app.globalData.parentAreaCode,
    // }).then(result => {
     
    // });
  },
  /**
   * 选择院子
   */
  bindSelectChangeYard:function(e){
    let key = e.currentTarget.dataset.value;
    let array = e.currentTarget.dataset.array;
    this.setData({
      yard: e.detail.value,
    });
  },
  /**
   * 提交
   */
  formSubmit: function (e) {
    let params = e.detail;
    let pages = getCurrentPages();
    let prevPage = pages[pages.length - 2];
    if (!this.data.yard){
      this.setData({
        error: "请选择院落!"
      });
    }else if (!app.removeAllSpace(params.problem)) {
      this.setData({
        error: "请输入物业报修内容!"
      });
    } else {
      app.confirm('提示', '你确定要提交吗？').then(result => {
        wx.showLoading({
          title: '保存中...',
        })
        let yardArray=this.data.yard.split(",");
        app.wxPostRequest("/mine/submitSuggestion", {
          "InfoFeedback.problem": params["problem"],
          "InfoFeedback.people_id": app.globalData.userInfo["people_id"],
          "InfoFeedback.yard_id": yardArray[1],
          "InfoFeedback.area_code": yardArray[0],
          "InfoFeedback.yard_name": yardArray[2],
        }).then(result => {
          wx.showToast({
            title: result.data.msg,
          });
          setTimeout(() => {
            prevPage.setData({
              operation: "add"
            });
            wx.navigateBack({
              delta: getCurrentPages()
            })
          }, 1000);
        });
      });
    }
  }
})